from urllib import request
import json,xlwt
list_all=[]
url_string = r'https://douban.uieee.com/v2/movie/top250'
with request.urlopen(url_string) as f:
    data = f.read().decode('utf-8')
    obj=json.loads(data)
    move_list = obj['subjects']
    for item in move_list:
        list = []
        list_name = []
        list.append(item['title'])
        list.append(item['genres'])
        list.append(item['rating']['average'])
        for j in item['casts']:
            list_name.append(j['name'])
        list.append(list_name)
        list.append(item['durations'])
        list_all.append(list)
    wbt = xlwt.Workbook()
    sheet = wbt.add_sheet('内容')
    tilte_list = ['电影名称', '电影类别', '电影评分', '电影主演', '电影时间']
    title = 0
    for zy in tilte_list:
        sheet.write(0, title, zy)
        title += 1
    x = 1
    for m in list_all:
        y = 0
        for n in m:
            if type(n) == list:
                str = ''
                for q in n:
                    str += q
                sheet.write(x, y, str)
            else:
                sheet.write(x, y, n)
            y += 1
        x += 1
    wbt.save('cb.xls')